package com.ruoyi.system.library.qywxlogin.controller;

import com.alibaba.fastjson2.JSONException;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.system.library.qywxlogin.tool.HttpInvoker;
import com.ruoyi.system.library.qywxlogin.tool.HttpUtils;
import com.ruoyi.system.library.qywxlogin.tool.WeChatAccessTokenUtils;
import com.ruoyi.system.library.qywxlogin.tool.WeChatUtils;

public class WeChatAssist {

    // 修改这里：方法参数可以更加内容进行修改，userid是必备的
    public static void sendWeChatMassage(String userId) throws JSONException {

        System.out.println(userId);

        //基础企业信息和secret
        String corpid = "ww3c8d31017de5aa90";
        String corpsecret = "RYETl8kUJI8Nec1aWAGh9Q5wnRCC42UzaCuCq4aN5EQ";//设备预约系统，已经修改好

        // 获取access_token json字符串
        String accessToken = WeChatAccessTokenUtils.getAccessToken(corpid, corpsecret);

        // 微信认证地址,该地址会获取一个code,并且该地址只能在微信客户端中打开
        String userInfoUrl = WeChatUtils.QY_WEIXIN_USERINFO_URL
                .replace("USERID", userId)
                .replace("ACCESS_TOKEN", accessToken);
        // 获取用户信息
        JSONObject userJson = HttpInvoker.exec(userInfoUrl, "GET", null);
        String name = userJson.getString("name");
        //String deptname = userJson.getString("main_department");
        System.out.println(userJson.toString());
        //user.setNickName(name);//姓名
        System.out.println(name);

    }

    public static void main(String[] args) {
        sendWeChatMassage("2021009003");
    }
}
